import request from './config'

/**
 * 获取知识库列表
 * @param {Object} params - 查询参数
 * @param {string} params.search - 搜索关键词
 * @param {number} params.status_filter - 状态过滤：0/1
 * @returns {Promise<Object>}
 */
export function getKnowledgeBases(params = {}) {
  return request({
    url: '/dk/knowledge/bases',
    method: 'get',
    params: params,
    headers: {
      Accept: 'application/json',
    },
  })
}

/**
 * 获取单个知识库详情
 * @param {number} baseId - 知识库ID
 * @returns {Promise<Object>}
 */
export function getKnowledgeBase(baseId) {
  return request({
    url: `/dk/knowledge/bases/${baseId}`,
    method: 'get',
    headers: {
      Accept: 'application/json',
    },
  })
}

/**
 * 获取知识条目列表
 * @param {Object} params - 查询参数
 * @param {number} params.skip - 跳过条数，默认0
 * @param {number} params.limit - 每页条数，默认20
 * @param {number} params.base_id - 所属知识库ID
 * @param {string} params.search - 搜索关键词
 * @param {number} params.status_filter - 状态过滤：0/1/2
 * @returns {Promise<Object>}
 */
export function getKnowledgeItems(params = {}) {
  const defaultParams = {
    skip: 0,
    limit: 20,
  }
  return request({
    url: '/dk/knowledge/items',
    method: 'get',
    params: { ...defaultParams, ...params },
    headers: {
      Accept: 'application/json',
    },
  })
}

/**
 * 获取单个知识条目详情
 * @param {number} itemId - 知识条目ID
 * @returns {Promise<Object>}
 */
export function getKnowledgeItem(itemId) {
  return request({
    url: `/dk/knowledge/items/${itemId}`,
    method: 'get',
    headers: {
      Accept: 'application/json',
    },
  })
}

/**
 * 搜索知识库内容
 * @param {Object} params - 查询参数
 * @param {string} params.query - 搜索查询
 * @param {number} params.limit - 返回条数限制
 * @param {number} params.relevance_threshold - 相关性阈值
 * @returns {Promise<Object>}
 */
export function searchKnowledge(params = {}) {
  const defaultParams = {
    limit: 10,
    relevance_threshold: 5,
  }
  return request({
    url: '/dk/knowledge/search',
    method: 'get',
    params: { ...defaultParams, ...params },
    headers: {
      Accept: 'application/json',
    },
  })
}
